// https://leetcode.cn/problems/valid-sudoku/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        int row[9][9];
        int col[9][9];
        int block[3][3][9];

        memset(row, 0, sizeof(row));
        memset(col, 0, sizeof(col));
        memset(block, 0, sizeof(block));

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                char numChar = board[i][j];
                if (numChar != '.') {
                    int num = numChar - '1';
                    row[i][num]++;
                    col[num][j]++;
                    block[i / 3][j / 3][num]++;

                    if (row[i][num] > 1 || col[num][j] > 1 || block[i / 3][j / 3][num] > 1) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
};